using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;

namespace Cupertino.Support.Converters;

//实现MarkupExtension可以直接在XAML的属性赋值中通过 {local:YourClassName} 的形式来创建一个新的实例
//而不是先定义资源，再通过StaticResource的方式引用
public class DepthConverter : MarkupExtension, IValueConverter
{
    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {   
        //因为int值被转换为object传递进来
        int depth = (int)value;
        Thickness margin = new Thickness(depth *20 , 0, 0, 0);
        return margin;
    }
    public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
    public override object? ProvideValue(IServiceProvider serviceProvider)
    {
        return this;
    }
}